Skip to content

feat(FOUR-34395): add core deploy sync for scripts, screens, and proc… - #9165

Merged
caleeli merged 1 commit into
feature/FOUR-34328from
FOUR-34395
Nov 13, 2026
Merged

caleeli merged 1 commit into
feature/FOUR-34328from
FOUR-34395

Conversation

@gproly

@gproly gproly commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

…esses

Port deploy/pull endpoints and BPMN portable reference resolution from package-skeleton. Register canonical /deploy-* routes and package-skeleton BC aliases; add feature tests for upsert flows.

https://processmaker.atlassian.net/browse/FOUR-34395

…esses

Port deploy/pull endpoints and BPMN portable reference resolution from package-skeleton. Register canonical /deploy-* routes and package-skeleton BC aliases; add feature tests for upsert flows.

https://processmaker.atlassian.net/browse/FOUR-34395
@cursor

cursor Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
New authenticated APIs upsert process/screen/script records and rewrite BPMN references; incorrect resolution or permissive routing could break workflows or overwrite assets by name.

Overview
Adds core deploy/pull APIs so scripts, screens, and processes can be synced by title/name without the package-skeleton plugin. New controllers upsert scripts (PHP + executor selection), screens (YAML), and processes (BPMN with XML validation), each with matching GET endpoints that return portable source.

Process deploy uses ProcessBpmnReferenceService to translate portable ${screen:…}, ${script:…}, and ${process:…} (including web-entry config) to stored IDs on deploy, and back to named refs on read; missing assets raise MissingBpmnReferenceException. Routes register canonical /api/1.0/deploy-* paths plus package-skeleton/* aliases for backward compatibility.

MCP process guidance/fields are updated to point portable BPMN refs at POST /api/1.0/deploy-process. Feature tests cover upsert, auth, reference round-trip, and Nayra executor preference.

Reviewed by Cursor Bugbot for commit 281f32a. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 281f32a. Configure here.

Comment thread routes/api.php
Route::post('package-skeleton/deploy-process', [DeployProcess::class, 'deployProcess'])
->name('package-skeleton.deploy-process');
Route::get('package-skeleton/process-bpmn', [DeployProcess::class, 'getProcessBpmn'])
->name('package-skeleton.process-bpmn');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy routes lack permission checks

High Severity

The new deploy and pull routes sit behind auth:api only. Neighboring script, screen, and process CRUD routes require create-*, edit-*, or view-*. Any authenticated user can upsert assets by title, including overwriting script code that later runs as that script’s run_as_user_id, and can pull full script source, screen YAML, and process BPMN by name.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 281f32a. Configure here.

return $php;
}

return ScriptExecutor::query()->orderBy('id')->first();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP deploy can bind wrong executor

Medium Severity

After php-nayra and php lookups fail, resolveForNewScript returns any executor by id. deploy-script always stores PHP source and copies that executor’s language, so a JavaScript or Python executor can be attached. The “no script executor” 422 then almost never fires whenever any non-PHP executor exists.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 281f32a. Configure here.

Comment thread routes/api.php

// Deploy / sync helpers (core). Canonical paths + package-skeleton aliases for BC.
Route::post('deploy-script', [DeployScript::class, 'deployScript'])->name('deploy-script');
Route::get('script-php', [DeployScript::class, 'getScriptPhp'])->name('script-php');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review

Severity: MEDIUM

Description: GET script-php and process-bpmn, including the package-skeleton aliases, are inside the auth:api group and do not require view-scripts or view-processes. getScriptPhp loads a Script by title and returns the published PHP. getProcessBpmn loads a Process by name and returns the BPMN, with script and screen ids rewritten to titles. Sibling reads require can:view-scripts and can:view-processes,process, and serialized processes hide bpmn.

Impact: Any authenticated account, including users who only have the default view-process-catalog permission, can list active process names and then download every process BPMN plus the published source of scripts those processes reference. That crosses the designer view boundary and exposes routing, assignments, and script code that can contain integration logic and secrets.

Remediation: Attach can:view-scripts to both script-php routes and can:view-processes to both process-bpmn routes, matching scripts.index and the BPMN download route. Keep the name lookup behind that gate so catalog users cannot read designer assets.

Comment thread routes/api.php

// Deploy / sync helpers (core). Canonical paths + package-skeleton aliases for BC.
Route::post('deploy-script', [DeployScript::class, 'deployScript'])->name('deploy-script');
Route::get('script-php', [DeployScript::class, 'getScriptPhp'])->name('script-php');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review

Severity: MEDIUM

Description: GET /api/1.0/script-php and GET /api/1.0/process-bpmn (and the package-skeleton aliases) return another user's published script PHP and process BPMN by exact name to any auth:api caller. The routes sit in the auth:api group with no can:view-scripts or can:view-processes middleware, and DeployScript::getScriptPhp / DeployProcess::getProcessBpmn never authorize the resolved model. Existing reads of the same data require those permissions: scripts.show and scripts preview use can:view-scripts,script, and processes.show plus processes/{process}/bpmn use can:view-processes,process. Process.bpmn is also $hidden on the model, so the normal process JSON resource does not return it.

Impact: A logged-in user in the default Requesters group, which has neither view-scripts nor view-processes, can read published PHP script source and the full BPMN of any process whose title or name they know. That is another user's designer-only definition: executable script logic (often queries, internal URLs, and embedded credentials) and the process graph that the authorized BPMN download keeps behind view-processes. Every browser login receives a Passport API cookie via CreateFreshApiToken, so this is a normal product session, not an admin or designer path. The caller must already know the exact title or name; the script and process index routes that would list them stay permission-gated.

Remediation: Add can:view-scripts to script-php and can:view-processes to process-bpmn, including the package-skeleton aliases, and authorize the resolved Script or Process before writing the body. Do not return source, BPMN, or asset ids unless that check passes.

Comment thread routes/api.php
Route::post('scripts/microservice/execution', [ScriptController::class, 'microserviceExecution']);

// Deploy / sync helpers (core). Canonical paths + package-skeleton aliases for BC.
Route::post('deploy-script', [DeployScript::class, 'deployScript'])->name('deploy-script');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review

Severity: HIGH

Description: POST /api/1.0/deploy-script, deploy-screen, and deploy-process (and the package-skeleton aliases) sit in the auth:api group with no can: middleware and no controller authorize() call. Any authenticated user, including a Requester without designer permissions, can create or overwrite a script, screen, or process by title or name. DeployScript looks up Script by global title, replaces code, and leaves run_as_user_id unchanged. HasVersioning publishes that code on save. The next script task loads the published version and ScriptRunner executes it as that run_as user, injecting an API token and environment variables. DeployProcess publishes attacker BPMN on an existing ACTIVE process; an inline script task with no scriptRef runs as Script::defaultRunAsUser(), the first administrator. DeployScreen writes config, watchers, and custom_css onto the screen with the same title. The paired GET routes return published script PHP, screen YAML, and process BPMN by name with the same missing gate.

Impact: A normal API user who was denied create/edit on scripts, screens, and processes can replace production automation. The next run of an overwritten script executes attacker PHP as the script's existing run_as user and receives that user's API token. Replacing a process the caller already knows by name can plant an inline script that the engine runs as the first administrator. That crosses the designer permission boundary into another user's credentials and into process, screen, and script definitions the caller is not allowed to change.

Remediation: Attach the same abilities as the sibling resource routes. On create require can:create-scripts, can:create-screens, or can:create-processes. On update resolve the row and require can:edit-scripts, can:edit-screens, or can:edit-processes for that model. Require the matching view ability on the GET-by-name routes. Do not publish code onto a script unless the caller may edit that script and control its run_as user. Keep the lookup inside the caller's authorized asset set rather than a global title or name match.

Comment thread routes/api.php
Route::post('scripts/microservice/execution', [ScriptController::class, 'microserviceExecution']);

// Deploy / sync helpers (core). Canonical paths + package-skeleton aliases for BC.
Route::post('deploy-script', [DeployScript::class, 'deployScript'])->name('deploy-script');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review

Severity: HIGH

Description: POST /api/1.0/deploy-script and POST /api/1.0/package-skeleton/deploy-script sit in the auth:api group with no can: middleware and no controller authorize() call. DeployScript upserts Script by global title, assigns the request body to script->code, and on update leaves run_as_user_id as already stored. save() publishes that code (versionable attribute code, draft default false). Any non-anonymous user can then POST scripts/execute/{id} with sync=true. Execution runs the stored code as run_as_user_id, injects that user's API_TOKEN plus every decrypted environment variable, and returns the script output to the caller.

Impact: A signed-in API user who lacks create-scripts and edit-scripts can publish PHP that the product will execute. Choosing a new title runs as the caller and still receives every stored environment-variable secret in the script environment. Updating an existing title keeps the previous run_as_user_id, so the same call executes as that user and the sync execute response can return that user's API token. That crosses the script create/edit permission boundary and turns a low-privilege account into the run-as user's API credential and the instance's script secrets.

Remediation: Gate deploy-script the same way as the script resource routes: can:create-scripts when no row exists, and can:edit-scripts against the resolved script on update (including the project-asset check in CustomAuthorize). On update, change run_as_user_id only when the caller is allowed to act as the target user; otherwise keep the existing identity only for callers who already pass edit-scripts on that script. Apply the same middleware to the package-skeleton alias.

Comment thread routes/api.php
Route::get('script-php', [DeployScript::class, 'getScriptPhp'])->name('script-php');
Route::post('deploy-screen', [DeployScreen::class, 'deployScreen'])->name('deploy-screen');
Route::get('screen-yaml', [DeployScreen::class, 'getScreenYaml'])->name('screen-yaml');
Route::post('deploy-process', [DeployProcess::class, 'deployProcess'])->name('deploy-process');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review

Severity: MEDIUM

Description: POST /api/1.0/deploy-process and POST /api/1.0/package-skeleton/deploy-process are inside the auth:api group and have no can: middleware. DeployProcess::upsertProcessByName loads any published Process by the caller-supplied name, and on a hit replaces bpmn and saveOrFail(). On a miss it inserts an ACTIVE process owned by the caller. Process does not limit versionable attributes, so HasVersioning publishes a non-draft process_versions row on that save. New executions load that published version through getPublishedVersion(). Canonical POST /processes requires can:create-processes and PUT /processes/{process}/update-bpmn requires can:edit-processes,process. DeployProcess never calls those gates or ProcessPolicy::edit, so a locked PM Block process is not rejected here either.

Impact: Any authenticated API user who lacks create-processes and edit-processes can publish a new ACTIVE process or replace the BPMN of an existing process by name. That BPMN is the definition new requests, call activities, and signal starts run, including task, screen, script, and call-activity bindings. This is a bypass of the process-design permission boundary: a participant can change how other users' future cases are routed and which existing screens and scripts they execute. ProcessPolicy::edit is the only core PM Block lock, and this path does not call it; the canonical can:edit-processes middleware also does not invoke that policy method, so the regression versus the existing API is the missing create/edit permission check.

Remediation: Before upsert, if no process exists require create-processes. If one exists, authorize edit on that Process (ProcessPolicy::edit) so both edit-processes and an imported locked PM Block are enforced. Do not assign bpmn or save until that check passes. Apply the same middleware or checks to both deploy-process route names.

return $parsedData;
}

$screen = Screen::where('title', $name)->first();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review

Severity: MEDIUM

Description: POST /api/1.0/deploy-screen and POST /api/1.0/package-skeleton/deploy-screen are only behind auth:api. Any logged-in user, including a default Requester who lacks create-screens and edit-screens, can create a screen or replace the screen whose title matches name. yml_content is exempt from SanitizeInput and is copied onto config, computed, watchers, and custom_css. Screen::save() publishes a non-draft version because Screen does not limit versionable attributes. Task and request UIs then load that latest published version and pass config, custom_css, watchers, and computed into the screen renderer.

Impact: A low-privilege authenticated user can change the form that other participants see and submit. That crosses the screen-editor boundary the rest of the API enforces with can:create-screens and can:edit-screens,screen: the attacker can alter collected fields, hide or replace controls, and supply the custom CSS, watchers, and computed properties the task and request renderers apply. Impact is the shared published screen document, not server takeover.

Remediation: On both deploy-screen routes, authorize before save: can:create-screens when the title does not exist, and can:edit-screens on the resolved Screen when it does, including the same project-asset check CustomAuthorize uses for screens.update. Reject the write when the caller fails that check. Validate type and the config, computed, watchers, and custom_css payload with the same rules as ScreenController::update before assignment.

@caleeli
caleeli merged commit 4b27368 into feature/FOUR-34328 Nov 13, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants